unit SiparisOlusturma;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FormClass, XPMan, StdActns, ActnList, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData,
  cxCheckBox, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid,
  StdCtrls, Buttons, ADODB, wwdbdatetimepicker, Menus;

type
  TfmSiparisOlusturma = class(TfmFormClass)
    GroupBox1: TGroupBox;
    btOlustur: TBitBtn;
    btKapat: TBitBtn;
    GroupBox2: TGroupBox;
    cxGrid1: TcxGrid;
    grdList: TcxGridDBTableView;
    grdListselected: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    btListele: TBitBtn;
    aqVerilenSiparis: TADOQuery;
    Label1: TLabel;
    dtBasTarih: TwwDBDateTimePicker;
    dtBitTarih: TwwDBDateTimePicker;
    sp_Entry: TADOStoredProc;
    dssp_Entry: TDataSource;
    grdListTip: TcxGridDBColumn;
    grdListYil: TcxGridDBColumn;
    grdListAy: TcxGridDBColumn;
    grdListFormTarih: TcxGridDBColumn;
    grdListFormNo: TcxGridDBColumn;
    grdListOnarimno: TcxGridDBColumn;
    grdListSiparisNo: TcxGridDBColumn;
    grdListSerino: TcxGridDBColumn;
    grdListStokkodu: TcxGridDBColumn;
    grdListCinsi: TcxGridDBColumn;
    grdListUstGrup: TcxGridDBColumn;
    grdListGrup: TcxGridDBColumn;
    grdListModel: TcxGridDBColumn;
    grdListMarka: TcxGridDBColumn;
    grdListTeknikTipi: TcxGridDBColumn;
    grdListTeknikPersonel: TcxGridDBColumn;
    grdListOnayDurum: TcxGridDBColumn;
    aqVerilenSiparishar: TADOQuery;
    PM: TPopupMenu;
    mnSe1: TMenuItem;
    SeimiKaldr1: TMenuItem;
    btTumunuSec: TBitBtn;
    btSecimKaldir: TBitBtn;
    grdListIslemTarih: TcxGridDBColumn;
    procedure btKapatClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btListeleClick(Sender: TObject);
    procedure btOlusturClick(Sender: TObject);
    procedure btTumunuSecClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmSiparisOlusturma: TfmSiparisOlusturma;

implementation
uses data, ana1;
{$R *.dfm}

procedure TfmSiparisOlusturma.btKapatClick(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfmSiparisOlusturma.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmSiparisOlusturma := nil;
end;

procedure TfmSiparisOlusturma.FormCreate(Sender: TObject);
begin
  inherited;
  dtBasTarih.Date := Date - 60;
  dtBitTarih.Date := Date + 1;
end;

procedure TfmSiparisOlusturma.FormShow(Sender: TObject);
begin
  inherited;
  anaform.CreateExport(Self);
  btListele.Click;
end;

procedure TfmSiparisOlusturma.btListeleClick(Sender: TObject);
begin
  inherited;
  if (Trim(dtBasTarih.Text) = '') or (Trim(dtBitTarih.Text) = '') then
  begin
    ShowMessage('Tarih Giriniz');
    Exit;
  end;

  with sp_Entry do
  begin
    Close;
    Parameters.ParamByName('@BasTarih').Value := dtBasTarih.Date;
    Parameters.ParamByName('@BitTarih').Value := dtBitTarih.Date;
    Open;
  end;
end;

procedure TfmSiparisOlusturma.btOlusturClick(Sender: TObject);
begin
  inherited;
  with sp_Entry do
  begin
    DisableControls;
    Filter := 'SELECTED=1';
    Filtered := True;
    First;

    aqVerilenSiparis.Close;
    aqVerilenSiparis.Open;

    aqVerilenSiparishar.Close;
    aqVerilenSiparishar.Open;

    aqVerilenSiparis.Append;
    aqVerilenSiparis.FieldByName('FormNo').Value := 0;
    aqVerilenSiparis.FieldByName('TalepTarih').Value := SadeceTarih;
    aqVerilenSiparis.FieldByName('istenilenTarih').Value := SadeceTarih;
    aqVerilenSiparis.FieldByName('Durum').Value := 1;
    aqVerilenSiparis.FieldByName('Firma').Value := 'Casper';
    aqVerilenSiparis.Post;

    try
      while not Eof do
      begin
        aqVerilenSiparishar.Append;
        aqVerilenSiparishar.FieldByName('SiparisRef').Value := aqVerilenSiparis.FieldByName('Ref').Value;
        aqVerilenSiparishar.FieldByName('FormNo').Value := sp_Entry.FieldByName('FormNo').Value;
        aqVerilenSiparishar.FieldByName('OnarimNo').Value := sp_Entry.FieldByName('OnarimNo').Value;
        aqVerilenSiparishar.FieldByName('SiparisNo').Value := sp_Entry.FieldByName('SiparisNo').Value;
        aqVerilenSiparishar.FieldByName('Stokkod').Value := sp_Entry.FieldByName('Stokkod').Value;
        aqVerilenSiparishar.FieldByName('Stokkodu').Value := sp_Entry.FieldByName('Stokkodu').Value;
        aqVerilenSiparishar.FieldByName('Cinsi').Value := sp_Entry.FieldByName('Cinsi').Value;
        aqVerilenSiparishar.FieldByName('TalepAdet').Value := 1;
        aqVerilenSiparishar.FieldByName('Durum').Value := 1;
        aqVerilenSiparishar.Post;

        Next;
      end;
    finally
      Filter := '';
      Filtered := False;

      btListele.Click;
      EnableControls;
    end;
  end;
end;

procedure TfmSiparisOlusturma.btTumunuSecClick(Sender: TObject);
var
  Counter: Integer;
begin
  inherited;
  sp_Entry.DisableControls;
  try
    for Counter := 0 to grdList.DataController.FilteredRecordCount - 1 do
    begin
      grdList.DataController.RecNo := 1 + grdList.DataController.FilteredRecordIndex[Counter];
      sp_Entry.Edit;
      sp_Entry.FieldByName('Selected').Value := TBitBtn(Sender).Tag;
      sp_Entry.Post;
    end;
  finally
    sp_Entry.EnableControls;
  end;
  sp_Entry.First;
end;

end.

